﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElingOA6_DSJCJ.Common;

namespace ElingOA6_DSJCJ.Controllers
{
    /// <summary>
    /// 局机关，镇乡网上考核统一入口
    /// </summary>
    /// 
    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class CheckIndex_IPController : Controller
    {
        private BLL.Entity entityBLL = new BLL.Entity();
        //
        // GET: /CheckIndex_IP/

        public ActionResult Index()
        {
            //底部
            ViewData["CopyRight"] = entityBLL.GetCopyRight(GlobalConstant.ENTITYNO);

            string login_IP = GenerateUtil.GetClientIPv4Address();//登陆的IP
            long login_IPLong = Fetch.Ip2Int(login_IP);
            bool contains = false;
            bool quanxian_JJG = false;
            bool quanxian_ZX = false;
            if (login_IP != "127.0.0.1")
            {
                string jjg_IP = System.Configuration.ConfigurationManager.AppSettings["jjg_IP"];//局机关IP段
                string[] arrayJJG_IP = jjg_IP.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arrayJJG_IP.Length; i++)
                {
                    string[] array = arrayJJG_IP[i].Split(new string[] { "～" }, StringSplitOptions.RemoveEmptyEntries);
                    for (int j = 0; j < array.Length; j++)
                    {
                        if (login_IPLong <= Fetch.Ip2Int(array[1]) && login_IPLong >= Fetch.Ip2Int(array[0]))
                        {
                            contains = true;
                            quanxian_JJG = true;
                        }
                    }
                }

                if (!contains)
                {
                    string zx_IP = System.Configuration.ConfigurationManager.AppSettings["zx_IP"];//镇乡IP段
                    string[] arrayZX_IP = zx_IP.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < arrayZX_IP.Length; i++)
                    {
                        string[] array1 = arrayZX_IP[i].Split(new string[] { "～" }, StringSplitOptions.RemoveEmptyEntries);
                        for (int j = 0; j < array1.Length; j++)
                        {
                            if (login_IPLong <= Fetch.Ip2Int(array1[1]) && login_IPLong >= Fetch.Ip2Int(array1[0]))
                            {
                                contains = true;
                                quanxian_ZX = true;
                            }
                        }
                    }

                }
            }
            else 
            {
                quanxian_JJG = true;
                quanxian_ZX = false;
            }
            ViewData["quanxian_JJG"] = quanxian_JJG;
            ViewData["quanxian_ZX"] = quanxian_ZX;

            if (quanxian_JJG == false && quanxian_ZX == false)
            {
                Response.Write("<script>alert('未授权');window.close();</script>");
                Response.Flush();
                Response.End();
            }
           
            return View();
        }
       
    }
}
